package br.com.tcc.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import br.com.tcc.enums.TipoCombustivel;

@Entity
@Table (schema = "tcc", name="combustivel")
public class Combustivel {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="idCombustivel")
	private Long idCombustivel;

	@Column(name="vl_preco", length = 100, nullable = false)
	private Double vlPreco;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="dt_registro", length = 200, nullable = true)
	private Date dtRegistro;
	
	@Enumerated(EnumType.STRING)
	@Column(length = 20)
	private TipoCombustivel tipoCombustivel;
	
	//1 posto possui N combustiveis
	//A anotacao abaixo configura basicamente a ideia de Foreign Key no BD
	//@JoinColumn(name = "posto_id", nullable = true)
	//@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	
	@ManyToOne(optional=true)
	@JoinTable(schema = "tcc", name = "postocombustivel", joinColumns = {
	@JoinColumn(name="combustivelId")
	},
	inverseJoinColumns = {
	@JoinColumn(name="postoId")
	}
	)
	
	private Posto posto;
	
	public Posto getPosto() {
		return posto;
	}
	public void setPosto(Posto posto) {
		this.posto = posto;
	}
	public TipoCombustivel getTipoCombustivel() {
		return tipoCombustivel;
	}
	public Double getVlPreco() {
		return vlPreco;
	}
	public void setVlPreco(Double vlPreco) {
		this.vlPreco = vlPreco;
	}
	public Date getDtRegistro() {
		return dtRegistro;
	}
	public void setDtRegistro(Date dtRegistro) {
		this.dtRegistro = dtRegistro;
	}
	public void setTipoCombustivel(TipoCombustivel tipoCombustivel) {
		this.tipoCombustivel = tipoCombustivel;
	}
	public Long getIdCombustivel() {
		return idCombustivel;
	}
	public void setIdCombustivel(Long idCombustivel) {
		this.idCombustivel = idCombustivel;
	}
	
}
